package com.jinly.ryder.ssh.command;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;

public class SshSessionUtil {
    public static Session connectSession(String host, int port) throws JSchException {
        JSch jsch = new JSch();
        jsch.addIdentity("~/.ssh/id_rsa");
        Session sshSession = jsch.getSession("root", host, port);
        sshSession.setConfig("StrictHostKeyChecking", "no");
        sshSession.connect(5000);
        return sshSession;
    }

    public static void closeSession(Session session) {
        try {
            if (session != null) session.disconnect();
        } catch (Exception e) {
        }
    }
}
